home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d19 / ckit15a.arc / CKITDEMO.C < prev    next >
C/C++ Source or Header  |  1990-08-13  |  12KB  |  331 lines

  1. #include    "ckit.h"             /* Include CKIT Header file!      */
  2. #include    "ckitdemo.h"         /* Include file for demo          */
  3. #pragma check_stack (off)
  4.  
  5.  
  6. /******************************************************************************
  7.  *                     Start of Main Program                                  *
  8.  *****************************************************************************/
  9. /* The main function MUST be prototyped as below using C's argc and
  10.  * argv array in your door program for use with CKIT.LIB.
  11.  */
  12.  
  13. main(int argc, char **argv) {     /* MUST HAVE MAIN PROTOTYPED AS SHOWN!  */
  14.  
  15. /******************************************************************************
  16. *                        USER adjustments                                     *
  17. * You will need to set these according to how you want CKIT to handle certain *
  18. * options.  See the CKIT.DOC for more information                             *
  19. * Also see CKITDEMO.H for program name                                        *
  20. *******************************************************************************/
  21.     FORCEOFFHOOK = TRUE;
  22.     USERSFILE = TRUE;
  23.     LOGOFFMSG = FALSE;
  24.     if (argc > 0) {
  25.         open_door(argv[1], argv[2]);
  26.         display_info();
  27.         menu();
  28.         close_door();
  29.         exit(0);
  30.     }
  31. }
  32.  
  33. /******************************************************************************
  34. *                       End of Main Program                                   *
  35. ******************************************************************************/
  36.  
  37. /******************************************************************************
  38. *                       Main Menu                                             *
  39. ******************************************************************************/
  40. void    menu(void) {
  41.  
  42.     newline();
  43.     if(display_file("ckit.m")) {   /* If error display_file() return NON_ZERO */
  44.         newline();
  45.     }
  46.     force_enter();
  47.     /* main command loop */
  48.     while(DUMP_USER != TRUE) {
  49.           /* prompt for input only if there is not a stacked command pending */
  50.         if ( strlen(cmdline) == 0) {
  51.             color(white);
  52.             newline();
  53.             s_puts("Main menu:\r\n");
  54.             color(red);
  55.             s_puts(" (I)  Display system information\r\n");
  56.             color(green);
  57.             s_puts(" (C)  Take a chance for more time online\r\n");
  58.             color(magenta);
  59.             s_puts(" (T)  Display a test pattern\r\n");
  60.             color(cyan);
  61.             s_puts(" (A)  Ansi graphics demo\r\n");
  62.             color(violet);
  63.             s_puts(" (D)  Display information on CKIT\r\n");
  64.             color(green);
  65.             s_puts(" (F)  Download CKIT.DOC using Zmodem \r\n");
  66.             color(red);
  67.             s_puts(" (Q)  Return to PCBoard\r\n");
  68.             color(yellow);
  69.             newline();
  70.             do {
  71.                 display_time();
  72.                 color(green);
  73.                 s_puts("Command? ");
  74.                 get_cmdline();          /* read input into 'cmdline'  */
  75.                 newline();
  76.  
  77.             } while( (DUMP_USER != TRUE) && ( strlen(cmdline) == 0 ));
  78.         }
  79.         if (DUMP_USER == TRUE) {
  80.             close_door();
  81.             exit(1);
  82.         }
  83.         if (get_nextpar()) {  /* scan next parameter from cmdline into par */
  84.  
  85.       /* process commands */
  86.             switch ( par[0] ) {
  87.                 case 'A':
  88.                 ansi_demo();
  89.                 break;
  90.                 case 'C':
  91.                 take_chance();
  92.                 break;
  93.                 case 'I':
  94.                 display_info();
  95.                 break;
  96.                 case 'T':
  97.                 test_pattern();
  98.                 break;
  99.                 case 'D':
  100.                 color(cyan);
  101.                 display_file(doc_filename);
  102.                 break;
  103.                 case 'F':
  104.                 color(cyan);
  105.                 filexfer();
  106.                 break;
  107.                 case 'Q':
  108.                 option = LOGOFF;
  109.                 close_door();
  110.                 exit(0);
  111.                 break;
  112.                 default:
  113.                 newline();
  114.                 color(magenta);
  115.                 s_putv("(",par,") is not allowed!  Try again:", NULL);
  116.                 *cmdline = NULL;
  117.                 newline();
  118.                 break;
  119.             }
  120.         }
  121.     }
  122. }
  123.  
  124. /******************************************************************************
  125. *                       Display User information                              *
  126. ******************************************************************************/
  127. void display_info(void) {
  128.  
  129.     char    s_out_str[34];
  130.     newline();
  131.     color(white);
  132.     s_putv(firstname,", Here is your User information:",NULL);
  133.     color(green);
  134.     newline();
  135.     s_putv("  Fullname        = ",fullname,"\r\n",NULL);
  136.     s_putv("  Phone numbers   = ",user.bphone," / ",user.phone,"\r\n",NULL);
  137.     s_putv("  City            = ",user.city,"\r\n",NULL);
  138.     s_putv("  Baud Rate       = ",baud_rate,"\r\n",NULL);
  139.     s_putv("  Last call date  = ",user.last_date," at ",user.last_time,"\r\n",NULL);
  140.     s_putv("  Minutes left    = ",itoa(min_left+time_credit,s_out_str,10),"\r\n",NULL);
  141.     s_putv("  Protocol is     = ",user.protocol,"\r\n",NULL);
  142.  
  143.     if(!PCB) {
  144.         s_putv("  Event runs at   = ",event_time,"\r\n",NULL);
  145.         s_putv("  # of Downloads  = ",dload_total, NULL);
  146.         s_putv("  Total K bytes   = ",download_Kbytes,",",NULL);
  147.         s_putv("  Today's K bytes = ",daily_bytes,NULL);
  148.         newline();
  149.         s_putv("  Allowed K bytes = ",itoa(dload_limit,s_out_str,10),"\r\n",NULL);
  150.         s_putv("  # of Uploads    = ",upload_total, NULL);
  151.         s_putv("  Total K bytes   = ",upload_Kbytes,"\r\n",NULL);
  152.     }
  153.     s_puts("  Graphics        = ");
  154.     if  (graphics) {
  155.         s_puts("ON");
  156.     } else {
  157.         s_puts("OFF");
  158.     }
  159.     newline();
  160.     s_putv("  Page length     = ", \
  161.           itoa(page_length,s_out_str,10),"\r\n", NULL);
  162.     color(yellow);
  163.     newline();
  164.     force_enter();
  165. /*
  166.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  167.  */
  168.  
  169. }
  170.  
  171. /******************************************************************************
  172. *                       ANSI Demo                                             *
  173. ******************************************************************************/
  174. void ansi_demo(void) {
  175.  
  176.     short x,y;
  177.     register    short  i;
  178.  
  179.     if (graphics) {                 /* Check if user is in graphics mode */
  180.         clr_screen();
  181.         for (y=2; y < 24; y++) {
  182.             pos_cursor(y,1);
  183.             s_puts("│");
  184.             pos_cursor(y,79);
  185.             s_puts("│");
  186.         }
  187.         x = 2;
  188.         pos_cursor(1,x);
  189.         for(i = 0; i <= 1; i++) {
  190.             while(x < 79) {
  191.                 s_puts("─");
  192.                 x++;
  193.             }
  194.             x = 2;
  195.             pos_cursor(23,x);
  196.         }
  197.         pos_cursor(1,1);
  198.         s_puts("┌");
  199.         pos_cursor(1,79);
  200.         s_puts("┐");
  201.         pos_cursor(23,1);
  202.         s_puts("└");
  203.         pos_cursor(23,79);
  204.         s_puts("┘");
  205.  
  206.         for(i = blue; i <= white; i++) {
  207.             color(i);
  208.             pos_cursor(i-8+3,11);
  209.             s_puts("ANSI Color display");
  210.         }
  211.         for(i = grey; i >= dkblue; i--) {
  212.             color(i);
  213.             pos_cursor(i+3, 50);
  214.             s_puts("ANSI Color display");
  215.         }
  216.         color(red);
  217.         pos_cursor(13,34);
  218.         s_puts("C - K I T");
  219.         color(yellow);
  220.         pos_cursor(16,14);
  221.         s_puts("This is only a SMALL sample of what C-Kit can do! ");
  222.         color(red);
  223.         pos_cursor(20,26);
  224.     } else {
  225.         newline();
  226.         s_puts("ANSI demo available only in GRAPHICS mode.\r\n");
  227.     }
  228.     force_enter();
  229.  
  230. /*
  231.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  232.  */
  233.     clr_screen();
  234. }
  235.  
  236. /*****************************************************************************
  237.  *  Open  door                                                               *
  238.  *****************************************************************************/
  239. void    test_pattern(void) {
  240.     int  i;
  241.  
  242.     newline();
  243.     for (i = 1; i < 21; i++) {
  244.            s_puts("(1234567890-abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789)\r\n");
  245.     }
  246. /*
  247.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  248.  */
  249.  
  250. }
  251.  
  252.  
  253. /*****************************************************************************
  254.  *  Filexfer doc file                                                        *
  255.  *****************************************************************************/
  256. void    filexfer(void) {
  257.     char xfer_file[46];
  258.     strcpy(xfer_file, zmodem_send);
  259.     strcat(xfer_file, doc_filename);
  260.     color(green);
  261.     s_putv("\nReady to send ", doc_filename, ". Press <ENTER> to begin.", NULL);
  262.     while(DUMP_USER != TRUE) {
  263.           if( check_CR() ) {
  264.             break;
  265.         }
  266.     }
  267.     if(dos_shell(xfer_file)) {
  268.         s_puts("\n\aTransfer aborted");
  269.     } else {
  270.         s_puts("\nTransfer complete");
  271.     }
  272. /*
  273.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  274.  */
  275. }
  276.  
  277. /*****************************************************************************
  278.  *  Take a chance on on-line time                                            *
  279.  *****************************************************************************/
  280. void    take_chance(void) {
  281.     char    thinking_of[5];
  282.  
  283.     if(PCB) {
  284.         *cmdline = 0;
  285.         itoa(random(10),thinking_of,10);
  286.         if ( strlen(cmdline) == 0) {
  287.             color(cyan);
  288.             s_puts("I'm thinking of a number from 0 to 9.  If you guess the\r\n");
  289.             s_puts("number, you will be given an extra 10 minutes online.  If you\r\n");
  290.             s_puts("get it wrong, your time will be reduced by 2 minutes.\r\n");
  291.             newline();
  292.             color(yellow);
  293.             s_puts("What's your guess? ");
  294.             get_cmdline();
  295.             newline();
  296.         }
  297.         if (get_nextpar()) {  /* scan next parameter from cmdline into par */
  298.             if (!strcmpi(thinking_of, par)) {
  299.                 color(green);
  300.                 s_puts("That's right!  You get a 10 minute bonus!");
  301.                 adjust_time_allowed(10);
  302.             } else {
  303.                 color(blue);
  304.                 s_putv("Wrong! You lose 2 minutes! I was thinking of ", thinking_of,".",NULL);
  305.                 adjust_time_allowed(-2);
  306.             }
  307.         }
  308.     } else {
  309.             newline();
  310.             s_puts("Take chance only available with PCBOARD.SYS usage.\r\n");
  311.     }
  312. }
  313. /****************************************************************************
  314.  *      IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF         *
  315.  ****************************************************************************/
  316. #if COMPILER == MICROSOFT
  317. int   random(short Modulo) {
  318.     short   seed;
  319.     check_time_left();
  320.     seed = system_time_HHMMSS[7] - 0x30;
  321.     return(RAND(seed));
  322. }
  323. #endif
  324.  
  325. /****************************************************************************
  326.  *     ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF    *
  327.  ****************************************************************************/
  328.  
  329. /****************************************************************************/
  330. /************************ E N D  O F   M O D U L E **************************/
  331.